package com.web.crawler.compare;

import com.web.crawler.compare.DocumentComparator;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class DocumentSimilarityApp {
    public static void main(String[] args) {
        try {
            Scanner scanner = new Scanner(System.in);

            System.out.println("请选择语言：(1-英文, 2-中文):");
            int langChoice = scanner.nextInt();
            scanner.nextLine();

            String folderPath = langChoice == 1 ? "C:\\Users\\jf\\IdeaProjects\\web-crawler\\documents\\en" :
                    "C:\\Users\\jf\\IdeaProjects\\web-crawler\\documents\\zh";

            DocumentComparator comparator = new DocumentComparator(folderPath);

            while (true) {
                System.out.println("\n菜单:");
                System.out.println("1. 比较两个指定文档");
                System.out.println("2. 查找与指定文档最相似的文档");
                System.out.println("3. 查找所有可能重复的文档");
                System.out.println("4. 退出");
                System.out.print("请输入您的选择: ");

                int choice = scanner.nextInt();
                scanner.nextLine(); // 消耗换行符
                //List<String> docNames = new ArrayList<>();
                switch (choice) {
                    case 1:
//                        System.out.println("可用文档:");
//                        docNames = comparator.getDocumentNames();
//                        for (int i = 0; i < docNames.size(); i++) {
//                            System.out.println(i + ": " + docNames.get(i));
//                        }

                        System.out.print("请输入第一个文档序号: ");
                        int doc1 = scanner.nextInt();
                        System.out.print("请输入第二个文档序号: ");
                        int doc2 = scanner.nextInt();
                        scanner.nextLine(); // 消耗换行符

                        comparator.compareTwoDocuments(doc1, doc2);
                        break;

                    case 2:
//                        System.out.println("可用文档:");
//                        docNames = comparator.getDocumentNames();
//                        for (int i = 0; i < docNames.size(); i++) {
//                            System.out.println(i + ": " + docNames.get(i));
//                        }

                        System.out.print("请输入要比较的文档序号: ");
                        int targetDoc = scanner.nextInt();
                        scanner.nextLine(); // 消耗换行符

                        comparator.findMostSimilarDocument(targetDoc);
                        break;

                    case 3:
                        System.out.print("请输入相似度阈值 (0.0-1.0): ");
                        double threshold = scanner.nextDouble();
                        scanner.nextLine(); // 消耗换行符

                        comparator.findDuplicateDocuments(threshold);
                        break;

                    case 4:
                        System.out.println("正在退出...");
                        return;

                    default:
                        System.out.println("无效选择，请重新输入。");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            System.err.println("文档处理错误: " + e.getMessage());
        }
    }
}